web/src/pages/[...listing].astro
490 lines · 13774 bytes
1---
2import Layout from '@layouts/Layout.astro';
3import ListingHero from '@components/things/ListingHero.astro';
4import ServiceList from '@components/things/ServiceList.astro';
5import Comments from '@components/things/Comments.svelte';
6import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
7import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
8import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
9import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro';
10import IosAppDetailedInfo from '@components/things/IosAppDetailedInfo.astro';
11import AndroidAppDetailedInfo from '@components/things/AndroidDetailedInfo.astro';
12import DiscordDetailedInfo from '@components/things/DiscordDetailedInfo.astro';
13import RedditDetailedInfo from '@components/things/RedditDetailedInfo.astro';
14import SocialShare from '@components/form/Social.astro';
15import DataActions from '@components/things/DataActions.svelte';
16import type { AwesomePrivacy, Section, Service } from '../types/Service';
17import { fetchData, slugify } from '@utils/fetch-data';
18import { codebergUrl } from '@utils/parse-markdown';
19import { fetchChangelog } from '@utils/fetch-changelog';
20import { fetchGitHubStats } from '@utils/fetch-repo-info';
21import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
22import { fetchWebsiteInfo } from '@utils/fetch-website-info';
23import { fetchDockerData } from '@utils/fetch-docker-instructions';
24import { fetchIosInfo } from '@utils/fetch-ios-info';
25import { fetchAndroidInfo } from '@utils/fetch-android-info';
26import { fetchPlexusInfo } from '@utils/fetch-plexus-info';
27import { fetchDiscordInfo } from '@utils/fetch-discord-info';
28import { fetchRedditInfo } from '@utils/fetch-reddit-info';
29import { site } from '@utils/config';
30import Button from '@components/form/Button.astro';
31
32interface Props extends Service {
33 slug: string;
34 parentSection: Section;
35 categoryName: string;
36}
37
38const {
39 name,
40 description,
41 url,
42 github,
43 codeberg,
44 git,
45 tosdrId,
46 discordInvite,
47 subreddit,
48 iosApp,
49 androidApp,
50 parentSection,
51 categoryName,
52} = Astro.props;
53
54const makeKeyWordTag = () => {
55 const keywords = [
56 `open source ${parentSection.name}`,
57 `${parentSection.name} comparison`,
58 ...(parentSection.alternativeTo || []).map(
59 (alt: string) => `${alt} alternative`,
60 ),
61 ...(parentSection.services || []).map((serv: Service) => `${serv.name} vs`),
62 'private',
63 'ad free',
64 'encrypted',
65 'open source software',
66 'privacy respecting apps',
67 'free tools',
68 ];
69 return keywords.join(', ');
70};
71
72const makePageTitle = () => {
73 return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
74};
75
76const makeBreadcrumbs = () => {
77 return [
78 { name: 'Home', item: '/' },
79 { name: categoryName, item: slugify(categoryName) },
80 {
81 name: parentSection.name,
82 item: `${slugify(categoryName)}/${slugify(parentSection.name)}`,
83 },
84 {
85 name: name,
86 item: `${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`,
87 },
88 ];
89};
90
91const makeDescriptionTag = () => {
92 let desc = `Analysis of ${name}, and other privacy-respecting ${parentSection.name} `;
93 if (parentSection.services) {
94 desc += `Compare ${parentSection.services.map((s: Service) => s.name).join(' vs ')} more apps. `;
95 }
96 if (parentSection.alternativeTo && parentSection.alternativeTo.length > 0) {
97 desc += `The best secure encrypted alternatives to ${parentSection.alternativeTo.join(', ')}. `;
98 }
99 desc += 'All this, and many more free and awesome tools and software.';
100 return desc;
101};
102
103const filterServices = () => {
104 return parentSection.services.filter((s: Service) => s.name !== name);
105};
106
107export async function getStaticPaths() {
108 const pages = await fetchData().then((data) => {
109 const results: Array<Props> = [];
110 if (!data || !data.categories) return results;
111 (data as AwesomePrivacy).categories.forEach((category) => {
112 category.sections.forEach((section) => {
113 const services = (section.services || []).map((service) => {
114 return {
115 slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
116 parentSection: section,
117 categoryName: category.name,
118 ...service,
119 };
120 });
121 results.push(...services);
122 });
123 });
124 return results;
125 });
126
127 return pages.map((props: Props) => {
128 return { params: { listing: props.slug }, props };
129 });
130}
131
132const makePaginationLinks = () => {
133 const allServices = parentSection.services || [];
134 const index = allServices.findIndex((item) => item.name === name);
135 const previousItem = index > 0 ? allServices[index - 1].name : null;
136 const nextItem =
137 index < allServices.length - 1 ? allServices[index + 1].name : null;
138 return { previous: previousItem, next: nextItem };
139};
140
141const { previous, next } = makePaginationLinks();
142
143const ignoredSites = ['github.com', 'wikipedia.'];
144
145const githubData = github ? await fetchGitHubStats(github) : null;
146const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
147const iosData = iosApp ? await fetchIosInfo(iosApp) : null;
148const androidData = androidApp ? await fetchAndroidInfo(androidApp) : null;
149const plexusData = androidApp ? await fetchPlexusInfo(androidApp) : null;
150const discordData = discordInvite
151 ? await fetchDiscordInfo(discordInvite)
152 : null;
153const redditData = subreddit ? await fetchRedditInfo(subreddit) : null;
154const dockerData = await fetchDockerData(name);
155const websiteData =
156 url && !ignoredSites.some((s) => url.includes(s))
157 ? await fetchWebsiteInfo(url)
158 : null;
159
160const serviceHistory = await fetchChangelog().then(({ entries }) => {
161 const isMatch = (c: { name: string; category: string; section: string }) =>
162 c.name === name &&
163 c.category === categoryName &&
164 c.section === parentSection.name;
165 const isHere = (m: {
166 name: string;
167 to: { category: string; section: string };
168 }) =>
169 m.name === name &&
170 m.to.category === categoryName &&
171 m.to.section === parentSection.name;
172 const results: Array<{
173 date: string;
174 type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
175 fields?: string[];
176 from?: { category: string; section: string };
177 previousName?: string;
178 pr?: import('@utils/fetch-changelog').ChangelogPr | null;
179 }> = [];
180 for (const e of entries) {
181 const s = e.changes?.services;
182 const added = (s?.added || []).find(isMatch);
183 const removed = (s?.removed || []).find(isMatch);
184 const modified = (s?.modified || []).find(isMatch);
185 const moved = (s?.moved || []).find(isHere);
186 const renamed = (s?.renamed || []).find(isHere);
187 if (added) results.push({ date: e.date, type: 'added', pr: e.pr });
188 else if (removed) results.push({ date: e.date, type: 'removed', pr: e.pr });
189 else if (modified)
190 results.push({
191 date: e.date,
192 type: 'modified',
193 fields: modified.fields,
194 pr: e.pr,
195 });
196 else if (renamed)
197 results.push({
198 date: e.date,
199 type: 'renamed',
200 previousName: renamed.previousName,
201 from: renamed.from,
202 pr: e.pr,
203 });
204 else if (moved)
205 results.push({ date: e.date, type: 'moved', from: moved.from, pr: e.pr });
206 }
207 return results;
208});
209
210const findPrivacyPolicyLink = () => {
211 if (!privacyData) return null;
212 const docs = privacyData?.parameters?.documents;
213 if (docs) {
214 const pp = (docs || []).find((doc) =>
215 doc.name.toLowerCase().includes('privacy policy'),
216 );
217 if (pp) return pp.url;
218 }
219 return `https://tosdr.org/en/service/${tosdrId}`;
220};
221
222const privacyPolicyLink = findPrivacyPolicyLink();
223
224const catSlug = slugify(categoryName);
225const secSlug = slugify(parentSection.name);
226
227const getApiEndpoint = () => {
228 return `https://api.awesome-privacy.xyz/${catSlug}/${secSlug}/${slugify(name)}`;
229};
230
231const makeSoftwareSchema = () => {
232 const operatingSystem = [
233 iosApp && 'iOS',
234 androidApp && 'Android',
235 url && 'Web',
236 ].filter(Boolean);
237 const plainDescription = (description || '')
238 .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
239 .replace(/[*_`~]/g, '')
240 .trim();
241 const codeRepository = github
242 ? `https://github.com/${github}`
243 : codeberg
244 ? codebergUrl(codeberg)
245 : git || null;
246 return {
247 '@context': 'https://schema.org',
248 '@type': 'SoftwareApplication',
249 name,
250 description: plainDescription || makeDescriptionTag(),
251 url,
252 applicationCategory: parentSection.name,
253 ...(operatingSystem.length && {
254 operatingSystem: operatingSystem.join(', '),
255 }),
256 ...(codeRepository && { codeRepository }),
257 };
258};
259---
260
261<Layout
262 title={makePageTitle()}
263 keywords={makeKeyWordTag()}
264 description={makeDescriptionTag()}
265 breadcrumbs={makeBreadcrumbs()}
266 customSchemaJson={makeSoftwareSchema()}
267>
268 <main>
269 <ListingHero
270 service={Astro.props}
271 parentSection={parentSection}
272 categoryName={categoryName}
273 privacyPolicyLink={privacyPolicyLink}
274 />
275 {
276 privacyData && privacyData.parameters?.points?.length > 0 && (
277 <section>
278 <h2>{name} Privacy Policy</h2>
279 <PrivacyPolicyDetails privacyData={privacyData} />
280 </section>
281 )
282 }
283 {
284 github && githubData && (
285 <section class="github-wrap">
286 <h2>{name} Source Code</h2>
287 <GitHubDetailedInfo gitHubData={githubData} repo={github} />
288 </section>
289 )
290 }
291 {
292 websiteData && (
293 <section>
294 <h2>{name} Website</h2>
295 <WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
296 </section>
297 )
298 }
299 {
300 ((androidData && !androidData.error) || plexusData) && (
301 <section>
302 <h2>{name} Android App</h2>
303 <AndroidAppDetailedInfo
304 androidData={androidData}
305 plexusData={plexusData}
306 />
307 </section>
308 )
309 }
310 {
311 iosData &&
312 typeof iosData === 'object' &&
313 Object.keys(iosData).length > 0 && (
314 <section>
315 <h2>{name} iOS App</h2>
316 <IosAppDetailedInfo url={url} iosData={iosData} />
317 </section>
318 )
319 }
320 {
321 dockerData && dockerData.found && (
322 <section>
323 <h2>{name} Docker</h2>
324 <DockerDetailedInfo docker={dockerData} />
325 </section>
326 )
327 }
328 {
329 (discordData || redditData) && (
330 <section>
331 <h2>{name} Socials</h2>
332 <div class="social-wrap">
333 {discordData && <DiscordDetailedInfo discordData={discordData} />}
334 {redditData && <RedditDetailedInfo redditData={redditData} />}
335 </div>
336 </section>
337 )
338 }
339
340 <section>
341 <h2>{name} Reviews</h2>
342 <Comments client:visible />
343 </section>
344
345 <section>
346 <h2>More {parentSection.name}</h2>
347 <ServiceList
348 services={filterServices()}
349 subHeading={true}
350 noGitHubMetrics={true}
351 buttonLink={`/${catSlug}/${secSlug}`}
352 categoryName={categoryName}
353 sectionName={parentSection.name}
354 />
355 </section>
356 <section>
357 <h2>About the Data: {name}</h2>
358 <DataActions
359 client:load
360 categoryName={categoryName}
361 sectionName={parentSection.name}
362 serviceName={name}
363 history={serviceHistory}
364 />
365 <h3>API</h3>
366 <p>
367 You can access {name}'s data programmatically via our API. Simply make a <code
368 >GET</code
369 > request to:
370 </p>
371 <pre><a href={getApiEndpoint()}><code>{getApiEndpoint()}</code></a></pre>
372 <p>
373 The REST API is free, no-auth and CORS-enabled. To learn more, view the <a
374 href="/api">Swagger Docs</a
375 > or read the <a href="/about#api">API Usage Guide</a>.
376 </p>
377 </section>
378
379 <section>
380 <h2>Share {name}</h2>
381 <p>
382 Help your friends compare {parentSection.name}, and pick
383 privacy-respecting software and services.<br />
384 Share {name} and Awesome Privacy with your network!
385 <div>
386 <SocialShare
387 url={`${site}/${catSlug}/${secSlug}/${slugify(name)} `}
388 title={`Checkout ${name}! \n`}
389 description={`Compare #${name} and other privacy-respecting ${parentSection.name} at ` +
390 `Awesome-Privacy.xyz, the free and open source list of private software alternatives. ` +
391 `#privacy #opensource #awesomeprivacy by @Lissy_Sykes`}
392 />
393 </div>
394 </p>
395 </section>
396
397 <div class="pagination-navigation">
398 {
399 previous ? (
400 <Button url={`/${catSlug}/${secSlug}/${slugify(previous)}`}>
401 <span>← Previous</span>
402 <p>{previous}</p>
403 </Button>
404 ) : (
405 <p class="nothing" />
406 )
407 }
408 <a href={`/${catSlug}/${secSlug}`} class="go-to-category">
409 View {parentSection.name} ({(parentSection.services || []).length})
410 </a>
411 {
412 next && (
413 <Button url={`/${catSlug}/${secSlug}/${slugify(next)}`}>
414 <span>Next →</span>
415 <p>{next}</p>
416 </Button>
417 )
418 }
419 </div>
420 </main>
421</Layout>
422
423<style lang="scss">
424 main {
425 margin: var(--space-lg) auto;
426 padding: var(--space-md);
427 width: var(--width-container);
428 max-width: var(--width-container-max);
429 position: relative;
430 @media (max-width: 768px) {
431 max-width: 95%;
432 padding: var(--space-sm);
433 margin: 0 auto;
434 }
435 }
436
437 section {
438 margin: var(--space-md) 0 var(--space-2xl) 0;
439 padding: var(--space-md);
440 min-height: 8rem;
441 position: relative;
442 border: var(--border-heavy);
443 box-shadow: var(--shadow-lg);
444 background: var(--accent-fg);
445 }
446
447 p {
448 margin: var(--space-xs) 0 var(--space-sm) 0;
449 }
450
451 h2 {
452 font-size: var(--text-3xl);
453 margin: -2rem 0 var(--space-md) -2rem;
454 box-shadow: var(--shadow-lg);
455 background: var(--accent);
456 color: var(--accent-fg);
457 width: fit-content;
458 padding: var(--space-xs) var(--space-sm);
459 @media (max-width: 768px) {
460 margin: -2rem auto var(--space-lg) auto;
461 }
462 }
463
464 h3 {
465 font-size: var(--text-lg);
466 margin-bottom: 0;
467 }
468
469 pre a {
470 text-decoration: none;
471 color: var(--foreground);
472 code {
473 background: var(--code-bg);
474 padding: 0.2rem 0.4rem;
475 border-radius: var(--curve-sm);
476 font-family: var(--font-code);
477 font-size: var(--text-sm);
478 @media (max-width: 768px) {
479 white-space: break-spaces;
480 }
481 }
482 }
483
484 .social-wrap {
485 display: flex;
486 gap: var(--space-md);
487 flex-wrap: wrap;
488 justify-content: space-between;
489 }
490</style>